#define _CRT_SECURE_NO_WARNINGS 1

//https://leetcode.cn/problems/backspace-string-compare/

class Solution {
public:
    bool backspaceCompare(string s, string t) {
        string s1, s2;
        for (auto ch : s)
        {
            if (s1.size() && ch == '#') s1.pop_back();
            else if (ch != '#') s1 += ch;
        }

        for (auto ch : t)
        {
            if (s2.size() && ch == '#') s2.pop_back();
            else if (ch != '#') s2 += ch;
        }

        if (s1 == s2) return true;
        return false;
    }
};